<template>
  <div class="home">
    <el-container>
      <el-header class="header">
        <Header />
      </el-header>

      <el-container class="aside-main-container">
        <el-aside width="240px">
          <Sidebar class="sidebar" />
        </el-aside>
        <el-main>
          <Main />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">
  // Home页面组件
  import Header from '@/components/Header.vue'
  import Sidebar from '@/components/Sidebar.vue'
  import Main from '@/components/Main.vue'

  import { ref, provide } from 'vue'


  /**
   * 滚动到顶部, 用于给子组件使用
   * 注入到provide中，子组件通过inject('scrollToTop')获取
   */
  const scrollToTop = () => {
    const mainEl = document.querySelector('.el-main')
    if (mainEl) {
      mainEl.scrollTo({
        top: 0,
        behavior: 'smooth'
      })
    }
  }

  // 注入到provide中，子组件通过inject('scrollToTop')获取
  provide('scrollToTop', scrollToTop)
</script>

<style scoped>
  .home {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 5px;
  }

  .aside-main-container {
    padding-top: 10px;
  }

  .sidebar {
    width: 100%;
    height: 100%;
  }

  .header {
    padding: 10px;
    height: 50px;
    padding-bottom: 30px;
  }

  .el-main {
    height: calc(100vh - 90px); /* 100vh - header height */
    overflow-y: auto;
    padding: 0;
  }

  .el-main::-webkit-scrollbar {
    width: 0;
    background: transparent;
  }
</style>
